package thinkingJava.chapter18;

import static util.Print.*;

import java.io.Externalizable;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

class Blips1 implements Externalizable {
	public Blips1() {
		print("Blips1 constructor()");
	}
	public void writeExternal(ObjectOutput out) throws IOException {
		print("Blips1.writeExternal");
	}
	public void readExternal(ObjectInput in) throws IOException,
			ClassNotFoundException {
		print("Blips1.readExternal");
	}

}
class Blips2 implements Externalizable {
	Blips2() {
		print("Blips2 constructor");
	}
	public void writeExternal(ObjectOutput out) throws IOException {
		print("Blips2.writeExternal");
	}
	public void readExternal(ObjectInput in) throws IOException,
			ClassNotFoundException {
		print("Blips2.readExternal");
	}

}
public class Blips {
	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		print("Constructor objects : ");
		Blips1 b1 = new Blips1();
		Blips2 b2 = new Blips2();
		ObjectOutputStream out = new ObjectOutputStream(
				new FileOutputStream("Blips.out"));
		out.writeObject(b1);
		out.writeObject(b2);
		out.close();
		ObjectInputStream in = new ObjectInputStream(
				new FileInputStream("Blips.out"));
		print("Recovering b1");
		b1 = (Blips1) in.readObject();
//		print("Recovering b2");
//		b2 = (Blips2) in.readObject();
	}
}
